﻿using Gargoyle.Roton;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace Gargoyle.ZZT
{
    sealed public class Location
    {
        private Pointer pointer;

        public Location()
        {
            this.pointer = new Pointer(new byte[2]);
            X = 0;
            Y = 0;
        }

        public Location(Pointer ptr)
        {
            this.pointer = ptr;
        }

        public Location(byte newX, byte newY)
        {
            this.pointer = new Pointer(new byte[2]);
            X = newX;
            Y = newY;
        }

        public static bool operator ==(Location loc1, Location loc2)
        {
            return ((loc1.X == loc2.X) && (loc1.Y == loc2.Y));
        }

        public static bool operator !=(Location loc1, Location loc2)
        {
            return ((loc1.X != loc2.X) || (loc1.Y != loc2.Y));
        }

        public Location Add(Location source)
        {
            return new Location((byte)(X + source.X), (byte)(Y + source.Y));
        }

        public Location Add(Vector vector)
        {
            return new Location((byte)(X + vector.X), (byte)(Y + vector.Y));
        }

        public Location Clone()
        {
            return new Location(X, Y);
        }

        public void CopyFrom(Location source)
        {
            X = source.X;
            Y = source.Y;
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public Location Subtract(Location source)
        {
            return new Location((byte)(X - source.X), (byte)(Y - source.Y));
        }

        public Location Subtract(Vector vector)
        {
            return new Location((byte)(X - vector.X), (byte)(Y - vector.Y));
        }

        public Point ToPoint()
        {
            return new Point(X, Y);
        }

        public override string ToString()
        {
            return "Location (" + X.ToString() + ", " + Y.ToString() + ")";
        }

        public byte X
        {
            get
            {
                return pointer[0];
            }
            set
            {
                pointer[0] = value;
            }
        }

        public byte Y
        {
            get
            {
                return pointer[1];
            }
            set
            {
                pointer[1] = value;
            }
        }
    }
}
